package com.bz.security;

import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import lombok.Data;

@Data
public class AuthUserDto implements UserDetails {
    private Long                                   id;
    private String                                 username;
    private String                                 password;
    /**
     * 真实姓名
     */
    private String                                 name;

    private String                                 phone;

    // 帐户是否过期
    private boolean                                accountNonExpired     = true;
    // 帐户是否被冻结
    private boolean                                accountNonLocked      = true;
    // 帐户密码是否过期，一般有的密码要求性高的系统会使用到，比较每隔一段时间就要求用户重置密码
    private boolean                                credentialsNonExpired = true;
    // 帐号是否可用
    private boolean                                enabled               = true;
    // 用户角色
    private Collection<? extends GrantedAuthority> authorities;

    public AuthUserDto(String username, boolean enabled) {
        super();

        this.username = username;
        this.enabled = enabled;
    }

//    public AuthUserDto(UserEntity userDto, Collection<? extends GrantedAuthority> authorities) {
//        super();
//        if (null != userDto) {
//            this.id = userDto.getId();
//            this.username = userDto.getUsername();
//            this.password = userDto.getPassword();
//            this.name = userDto.getName();
//            this.phone = userDto.getPhone();
//            this.enabled = StringUtils.equals(userDto.getStatus(), "1");
//            this.urls = userDto.getUrls();
//            Map<String, UserRoleDto> rmap = new HashMap<>();
//            if (!CollectionUtils.isEmpty(userDto.getRoleList())) {
//                for (UserRoleDto r : userDto.getRoleList()) {
//                    rmap.put(r.getRoleCode(), r);
//                }
//            }
//
//            this.roleMap = rmap;
//        }
//
//        this.authorities = authorities;
//    }

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {

        return authorities;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return this.accountNonExpired;
    }

    // 帐户是否过期
    @Override
    public boolean isAccountNonLocked() {
        return this.accountNonLocked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return this.credentialsNonExpired;
    }

    @Override
    public boolean isEnabled() {
        return this.enabled;
    }

}
